package com.sasis.util.holder;

import com.sasis.model.User;

public class PrincipalContextHolder {
	
	private static final ThreadLocal localContext = new ThreadLocal();
	
	private User user;
	
	public static PrincipalContextHolder getPrincipalContext() {
		PrincipalContextHolder ctx = (PrincipalContextHolder) localContext.get();
		if (ctx == null) {
			ctx = new PrincipalContextHolder();
			localContext.set(ctx);
		}
		return ctx;
	}
	
	public static void initCurrentContext(User user) {
		PrincipalContextHolder ctx = getPrincipalContext();
		ctx.user = user;
	}
	
	public User getPrincipal() {
		return user;
	}

}
